<template>
  <div class="adminHandle">
    <h3>销假管理</h3>
    <div class="showmsg">
      <div class="tablelist">
        <template>
          <el-table
            :data="tableData"
            border
            style="width: 100%">
            <el-table-column
              prop="id"
              label="申请id"
              width="90px">
            </el-table-column>
            <el-table-column
              prop="startdate"
              label="开始时间">
            </el-table-column>
            <el-table-column
              prop="enddate"
              label="结束时间">
            </el-table-column>
            <el-table-column
              prop="isPass"
              label="审核"
              width="90px">
              <template slot-scope="scope">
                <img class="pic" v-show="scope.row.isPass" src="../../pages/admin/assets/correct.png">
                <img class="pic" v-show="!scope.row.isPass" src="../../pages/admin/assets/close.png">
              </template>
            </el-table-column>
            <el-table-column
              prop="flag"
              label="销假"
              width="90px">
              <template slot-scope="scope">
                <img class="pic" v-show="scope.row.flag" src="../../pages/admin/assets/correct.png">
                <img class="pic" v-show="!scope.row.flag" src="../../pages/admin/assets/close.png">
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              label="操作"
              width="120">
              <template slot-scope="scope">
                <el-button
                  @click.native.prevent="setflagback(scope.row)"
                  type="text"
                  size="medium"
                  :disabled="scope.row.flag">
                  我已返校
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'


  export default {
  name:"StudentBackAdmin",
  data() {
    return {
      tableData: [],
      submitData:{
        sNumber:'',
      }
    }
  },
  methods: {
    setflagback(rows) {
      rows.flagback = true
      this.submitData.sNumber=rows.sid


      axios.defaults.headers.common["token"] = this.token;
        axios.put((this.ip + '/leaveMsg/' + rows.id),JSON.stringify(this.submitData),{headers:
            {'Content-Type':'application/json'}}).then((response)=>{
          console.log(response)
          console.log(response.data)
        }).catch(function (error) {
          console.log(error);
        });

    }
  },
    mounted() {
      this.ip = localStorage.getItem('ip');
      this.token = sessionStorage.getItem('token');

      axios.defaults.headers.common["token"] = this.token;
      axios.get((this.ip + '/leaveMsg/')).then((response)=>{
        console.log(response)
        console.log(response.data)
        for(let i=0;i<response.data.length;i++){
          this.tableData.push({
            id:response.data[i].id,
            sid:response.data[i].snumber,
            startdate:response.data[i].startDate,
            enddate:response.data[i].endDate,
            isPass:response.data[i].isPass,
            flag:response.data[i].flag
          })
        }
      }).catch(function (error) {
        console.log(error);
      });
    }
}
</script>

<style scoped>
.adminHandle{
  width: 100%;
  padding: 5px 10px 0px 10px;
  margin: 20px 100px 0px 100px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.3);

}
.tablelist{
  padding-top: 20px;
}
.pic{
  width: 20px;
  height: 20px;
}
</style>


